package com.lz.ovuola.service.assembler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lz.ovuola.entity.PhysiologicalDataDo;
import com.lz.ovuola.service.dto.PhysiologicalDataDto;
import com.lz.ovuola.util.exception.BusinessException;
import com.lz.ovuola.util.exception.msg.CommonMsgEnum;
import com.lz.ovuola.util.threadlocal.UserContextHolder;

/**
 * 包装工具
 * 
 * @author fz
 *
 */
public class PhysiologicalDataAssembler implements
		Assembler<PhysiologicalDataDto> {

	// private final LoginUserDto EMPTY_DATA = new LoginUserDto();
	private Logger logger = LoggerFactory
			.getLogger("PhysiologicalDataAssembler");
	private static final PhysiologicalDataAssembler ASSEMBLER = new PhysiologicalDataAssembler();

	private PhysiologicalDataAssembler() {
		super();
	}

	@Override
	public PhysiologicalDataDto toDto(Object object) throws Exception {
		if (object instanceof PhysiologicalDataDo) {
			PhysiologicalDataDo physiologicalDataDo = (com.lz.ovuola.entity.PhysiologicalDataDo) object;
			PhysiologicalDataDto physiologicalDataDto = new PhysiologicalDataDto();
			physiologicalDataDto
.setEstimateNextStartTime(physiologicalDataDo
					.getEstimateNextStartTime());
			physiologicalDataDto
.setEstimateOvulationTime(physiologicalDataDo
					.getEstimateOvulationTime());
			physiologicalDataDto
					.setEstimateOvulationTimeDescription(physiologicalDataDo
							.getEstimateOvulationTimeDescription());
			physiologicalDataDto.setFormula(physiologicalDataDo.getFormula());
			physiologicalDataDto.setPhysiologicalStage(physiologicalDataDo
					.getPhysiologicalStage());
			physiologicalDataDto
					.setPregnancyRateDescription(physiologicalDataDo
							.getPregnancyRateDescription());
			physiologicalDataDto.setWaterContent(physiologicalDataDo
					.getWaterContent());
			return physiologicalDataDto;
		}
 else
 {
			logger.error(
					"---用户id：{},physiologicalDataDo转physiologicalDataDto过程中出现异常",
					UserContextHolder.get().getUserId());// UserContextHolder
			throw new BusinessException(
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getStatus(),
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getMsg());
		}
	}


	public static PhysiologicalDataAssembler getAssembler() {
		return ASSEMBLER;
	}

}
